package com.cskaoyan._11polymorphic._06ex;

/**
 * @description:
 * @author: 景天
 * @date: 2023/2/10 16:13
 **/

public class Demo {
    public static void main(String[] args) {
        ConfuciusFather cf = new Confucius();
        System.out.println(cf.age);//48
        cf.teach();//论语
        // cf.playGame(); //不能打游戏，因为父类没这个成员
        Confucius c = (Confucius) cf;
        System.out.println(c.age);//28
        c.playGame();
    }
}

class ConfuciusFather{
    int age = 48;
    public void teach(){
        System.out.println("我要教Java");
    }
}
class Confucius extends ConfuciusFather{
    int age = 28;
    public void playGame(){
        System.out.println("孔子喜欢玩大乱斗！");
    }
    @Override
    public void teach() {
        System.out.println("我会教论语");
    }
}
